<template>
  <div style="height: 600px">
    <el-table
        :data="list" border style="width: 100%" >
      <el-table-column prop="username" label="学生" width="180">
      </el-table-column>
      <el-table-column prop="room_name" label="教室" width="180">
      </el-table-column>
      <el-table-column prop="begin_time" label="开始时间">
      </el-table-column>
      <el-table-column prop="end_time" label="截止时间">
      </el-table-column>
      <el-table-column label="操作" #default="scope">
        <el-button @click="agreeAppoint(scope.row,scope.index)" type="primary">同意</el-button>
        <el-button @click="disagreeAppoint(scope.row,scope.index)" type="danger">拒绝</el-button>
      </el-table-column>
    </el-table>
  </div>
</template>

<script>
import {IP} from "@/config";
import axios from "axios";
import moment from 'moment'
export default {
  name: "disposeAppoint",
  data(){
    return{
      list:[],
    }
  },
  methods:{
    agreeAppoint(row,index){
      let url = IP + "appointment/disposeAppoint/agree"
      axios.post(url,{id:row.id}).then(res => {
        if(res.data.code === 0){
          this.$message({
            message: res.data.data.status,
            type: 'success'
          });
        }
        this.list.splice(index,1)
      }).catch(error => {
        console.log(error)
      })
    },
    disagreeAppoint(row,index){
      let url = IP + "appointment/disposeAppoint/disagree"
      axios.post(url,{id:row.id}).then(res => {
        if(res.data.code === 0){
          this.$message({
            message: res.data.data.status,
            type: 'success'
          });
        }
        this.list.splice(index,1)
      }).catch(error => {
        console.log(error)
      })
    }
  },
  mounted() {
    let url = IP + "appointment/getAllDisAgreeAppoint"
    axios.post(url).then(res => {
      console.log(res)
      this.list = res.data.data.appointList
      this.list.forEach((item,index)=>{
        let begin = this.list[index]["begin_time"]
        let end = this.list[index]["end_time"]
        this.list[index]["begin_time"] = moment(begin).format("YYYY-MM-DD HH:mm:ss");
        this.list[index]["end_time"] = moment(end).format("YYYY-MM-DD HH:mm:ss");
      })
    }).catch(error => {
      console.log(error)
    })
  }
}
</script>

<style scoped>

</style>